/*
	Given an array of integers, return indices of the two numbers such that they add up to a specific target.
	You may assume that each input would have exactly one solution, and you may not use the same element twice.
*/

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
#include <stdlib.h>
int* twoSum(int* nums, int numsSize, int target) {
    int i, j;
    int *result = (int*)malloc(sizeof(int) * 2);
    for(i = 0 ; i < numsSize ; i++){
    	for( j = i + 1 ; j < numsSize ; j++){
	    	if( nums[i] + nums[j] == target	){
	    		*result = nums[i];
	    		*(result + 1) = nums[j];
	    		return result;
	    	}
	    }
    }
}

int main(){
	int a[4] = {1,2,3,5	};
	int *result = twoSum(a, 4, 5), *p;
	p = result + 2;
	while( result < p){
		printf("%d\n", *result++);
	}
	
	return 0;
}
